package cn.puge.mertisfront.service.impl;

import cn.puge.mertisfront.entity.PugeContents;
import cn.puge.mertisfront.entity.conVo.ContentVo;
import cn.puge.mertisfront.entity.conVo.ContentwoVo;
import cn.puge.mertisfront.mapper.PugeContentsMapper;
import cn.puge.mertisfront.service.PugeContentsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LIJW
 * @since 2020-08-30
 */
@Service
public class PugeContentsServiceImpl extends ServiceImpl<PugeContentsMapper, PugeContents> implements PugeContentsService {

    @Override
    public List<ContentVo> getAllContent() {


        List<PugeContents> pugeContents = baseMapper.selectList(null);

        //最终结果封装
        List<ContentVo> contentVoList = new ArrayList<>();

        for (PugeContents pugeContents1 : pugeContents){

            ContentVo contentVo = new ContentVo();

            List<ContentwoVo> contentwoVoList = new ArrayList<>();

              if (pugeContents1.getId().equals(pugeContents1.getConid())){

                     contentVo.setId(pugeContents1.getId());
                     contentVo.setConame(pugeContents1.getConame());

                       for (PugeContents pugeContents2 : pugeContents){

                           ContentwoVo contentwoVo = new ContentwoVo();

                           if (pugeContents1.getId().equals(pugeContents2.getConid()) && !pugeContents2.getId().equals(pugeContents2.getConid())){
                               BeanUtils.copyProperties(pugeContents2,contentwoVo);
                               contentwoVoList.add(contentwoVo);
                           }
                       }
                  contentVo.setContentwoVoList(contentwoVoList);
                  contentVoList.add(contentVo);
              }

        }

        return contentVoList;
    }
}
